package com.clouddot.baipai.ui.dialog.H_Dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.clouddot.baipai.R;


/**
 * Created by wxy on 2018/4/2.
 */

public class H_SettingDailog {
    private Dialog Dialog;
    private ConstraintLayout constraintLayout;
    private Context context;
    private EditText pass;
    private LinearLayout calce , sure ;
    private View view;

    public H_SettingDailog(Context context) {
        this.context = context;
        initView();

    }

    public LinearLayout[] getBtnView(){
        LinearLayout[] imageViews =new LinearLayout[2];
        sure = constraintLayout.findViewById(R.id.sure);
        calce = constraintLayout.findViewById(R.id.cancle);
        imageViews[0] = sure;
        imageViews[1] = calce;
        return imageViews;
    }

    public EditText getPass(){
        if(pass == null){
            pass =  constraintLayout.findViewById(R.id.edit);
        }
        return pass;
    }

    private void initView() {
        constraintLayout = (ConstraintLayout) LayoutInflater.from(context).inflate(R.layout.h_d_settingdialog, null);
    }

    public void showDialog() {

        Dialog = getDialog();
        Dialog.show();

    }

    public void closeDialog() {
        if (Dialog != null)
        {
            Dialog.dismiss();
        }
    }

    public Dialog getDialog() {
        if (Dialog == null)
        {
            Dialog = new Dialog(context,R.style.ActionSettingDialogStyle);
        }


        Dialog.setContentView(constraintLayout);

        Window dialogWindow = Dialog.getWindow();

        view = dialogWindow.getDecorView();
        lock();

        view.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int i) {
                lock();
            }
        });


        view.setPadding(0,100,0,0);

        dialogWindow.setGravity( Gravity.TOP);

        WindowManager.LayoutParams lp = dialogWindow.getAttributes();

        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;

        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;


        dialogWindow.setAttributes(lp);

        Dialog.setCancelable(false);

        return Dialog;
    }
    private void lock(){
        int uiFlags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE;
        view.setSystemUiVisibility(uiFlags);
    }


}



